package com.his.his_system.controller.VisitController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.his.his_system.common.util.ResultAdvice;
import com.his.his_system.domain.DzmHisCareHistory;
import com.his.his_system.domain.DzmPatient;
import com.his.his_system.service.DefaultService;
import com.his.his_system.service.DzmPatientService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 患者库
 * @author 余襄元
 */
@RestController
@RequestMapping("/his/sad/patient/")
public class PatientController {

    @Resource
    private DzmPatientService dzmPatientService;

    @Resource
    private DefaultService defaultService;

    @Resource
    private YxyTodo yxyTodo;

    /**
     * 获取本医院所有患者
     * @return
     */
    @GetMapping("getAllPatient")
    public ResultAdvice< List<DzmPatient> > getAllPatient(){
        QueryWrapper<DzmPatient> queryWrapper = new QueryWrapper();
        queryWrapper.eq("hospital_id",yxyTodo.getHospitalid());
        return ResultAdvice.success(dzmPatientService.list(queryWrapper),"成功");
    }


    /**
     * 模糊查询获取本医院所有患者
     * @return
     */
    @GetMapping("selectpatientbynameAndphp")
    public ResultAdvice< List<DzmPatient> > selectpatientbynameAndphp(String name,String php){
        QueryWrapper<DzmPatient> queryWrapper = new QueryWrapper();
        queryWrapper.eq("hospital_id",yxyTodo.getHospitalid());
        queryWrapper.like("name",name).like("mobile",php);
        return ResultAdvice.success(dzmPatientService.list(queryWrapper),"成功");
    }

    /**
     * 根据患者id查询所有病例
     * @param patientid 患者id
     * @return
     */
    @GetMapping("getAllHistoryByPatientId")
    public ResultAdvice<List<DzmHisCareHistory>> getAllHistoryByPatientId(Integer patientid){
        return ResultAdvice.success(defaultService.getAllHistoryByPatientId(patientid),"成功");
    }

    /**
     * 修改患者信息
     * @param dzmPatient
     * @return
     */
    @PostMapping("updatePatientInfo")
    public ResultAdvice updatePatientInfo(@RequestBody DzmPatient dzmPatient){
       dzmPatient.setUpdateTime((int)(System.currentTimeMillis()/1000));
        UpdateWrapper<DzmPatient> updateWrapper = new UpdateWrapper<>();
        boolean fig = dzmPatientService.updateById(dzmPatient);
        return fig?ResultAdvice.success("成功"):ResultAdvice.fail("失败");
    }
 }
